// /////////////////////////////////////////////////////////////////////////////
//
// Name:            SoundListenerComponent.h
// Author:          Michael Bartsch (ZCCdark203)
//
// Desc :           Declaration of the SoundListenerComponent class.
//
// License:         Copyright (C) 2009 Michael Bartsch and Contributors
//
//                  This program is free software: you can redistribute it
//                  and/or modify it under the terms of the zlib/libpng License.
//                  See main.cpp for conditions of distribution and use.
//
// /////////////////////////////////////////////////////////////////////////////

#ifndef __SOUNDLISTENERCOMPONENT_H__
#define __SOUNDLISTENERCOMPONENT_H__

// Include files
#include "../../dependencies.h"
#ifdef __COMPILE_WITH_SFML_AUDIO__
#include "../../core/EntityComponent.h"


// SoundListenerComponent class
//! Component wrapper of SFML's sf::Listener.
//!
//! <b>XML:</b>
//! \code
//! <SoundListenerComponent>
//!    <!-- Properties -->
//! </SoundListenerComponent>
//! \endcode
class SoundListenerComponent : public EntityComponent
{
public:

    // Initialisation and deinitialisation
    //! Constructor
    //! @param parent        The parent entity to which the component should be added.
    //! @param isMainListener Sets whether this is the main listener.
    SoundListenerComponent(Entity *parent, bool isMainListener = true);
    //! Deconstructor
    ~SoundListenerComponent();

    // Methods
    //! Checks if this listener is the main listener.
    bool getIsMainListener() const;

    //! Sets whether this listener is the main listener.
    //!
    //! <b>XML:</b>
    //! \code
    //! <isMainListener type="bool" value="" />
    //! \endcode
    //!
    //! @param value         Value to enable or disable this option.
    void setIsMainListener(bool value = true);

    // Events
    //! Updates the position of the component after its parent has been updated.
    //! @note For internal use only!
    void onPositionChange(void *p);
    //! Updates the rotation of the component after its parent has been updated.
    //! @note For internal use only!
    void onRotationChange(void *p);
    //! Pauses the component if the parent is paused.
    //! @note For internal use only!
    void onPause(void *p);
    //! Unpauses the component if the parent is unpaused.
    //! @note For internal use only!
    void onUnPause(void *p);

    // Serialization
    //! Serializes this object.
    //! @param attributes
    virtual bool onSerialization(SerializedAttributes *attributes);
    //! Deserializes this object.
    //! @param attributes
    virtual bool onDeserialization(SerializedAttributes *attributes);

private:

    // Static Members
    static SoundListenerComponent *mMainListener;

    // Members
    vector3df mPosition;
    vector3df mRotation;

    bool mIsMainListener;
    bool mWasMainListener; // For event handeling
};

#endif // __COMPILE_WITH_SFML_AUDIO__

#endif
